<template>
	<view class="content">
		<view class="block screen-block">
			<view class="screen-item">
				<picker :range="category" @change="bindCategory" range-key="hotelName" class="picker category">
					{{category[categoryActive].hotelName?category[categoryActive].hotelName:''}}
				</picker>
				<view class="iconfont icon-xiasanjiaoxing"></view>
			</view>
			<view class="screen-item">
				<picker :range="businessArea" @change="bindBusinessArea" range-key="shoppingName"
					class="picker businessArea">
					{{businessArea[businessAreaActive].shoppingName?businessArea[businessAreaActive].shoppingName:''}}
				</picker>
				<view class="iconfont icon-xiasanjiaoxing"></view>
			</view>
			<!-- <view class="screen-item">
				<view :class="optionActive==1?'active':''" @click="bindOption(1)" class="option">离我最近</view>
			</view>
			<view class="screen-item">
				<view :class="optionActive==2?'active':''" @click="bindOption(2)" class="option">好评优先</view>
			</view> -->
		</view>
		<!-- <view class="block label-block">
			<view v-for="(item,index) in label" :key="item.id" @click="keyword=item.value" class="label-item">
				{{item.value}}
			</view>
		</view> -->
		<view class="block list-block">
			<navigator hover-class="none" :url="'/pages/hotel/list?id='+item.id" v-for="(item,index) in list"
				:key="item.id" class="list-item">
				<image mode="aspectFill" :src="item.picUrl" class="photo"></image>
				<view class="info-block">
					<view class="name-block">
						<view class="name">{{item.title}}</view>
						<view class="grade">{{item.star}}</view>
					</view>
					<view class="score-block">
						<view class="score">{{item.score}}</view>
						<view class="score-num">{{item.comNum}}评价</view>
						<view class="collect"> · {{item.collection}}收藏</view>
					</view>
					<view class="position-block">{{item.address}}</view>
					<view class="label-block">
						<view v-for="(item1,index1) in item.label" class="label-item">{{item1}}</view>
					</view>
					<view class="price">
						<view class="money">￥</view>{{item.price}}
						<view class="unit">起</view>
					</view>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	import {
		getfindAllHotelOd,
		getFindAllLikes,
		getViewListApi
	} from '@/api/hotel.js';
	import {
		getShoppingListApi
	} from '@/api/attractions.js';
	export default {
		data() {
			return {
				keyword: '',
				custom: null,
				category: [],
				label: [],
				categoryActive: 0,
				businessArea: [],
				businessAreaActive: 0,
				optionActive: 0,
				list: [

				],
				categoryActiveId: 0,
				businessAreaActiveId: 0


			}
		},
		methods: {
			bindCategory(e) {
				this.categoryActive = e.detail.value;
				this.findAllByList()
			},
			bindBusinessArea(e) {
				console.log(e);
				this.businessAreaActive = e.detail.value;
				this.findAllByList()
			},
			// bindOption(index) {
			// 	this.optionActive = index;
			// 	this.findAllByList()
			// },

			findAllByList() {
				if (this.category != null && this.category.length > 0) {
					this.categoryActiveId = this.category[this.categoryActive].id;
				}
				if (this.businessArea != null && this.businessArea.length > 0) {
					this.businessAreaActiveId = this.businessArea[this.businessAreaActive].id;
				}
				getfindAllHotelOd({
					hotelType: this.categoryActiveId,
					shopping: this.businessAreaActiveId,
					orderByType: this.optionActive
				}).then((res) => {
					console.log(res)
					if (res.code == 1) {
						if (res.info != null) {
							this.list = res.info;
						}
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			getViewList() {
				getViewListApi().then((res) => {
					if (res.code == 1) {
						this.category = res.data;
						this.categoryActive = 0;
						console.log(11111111)
						console.log(this.category)
					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					uni.hideLoading();
					uni.showToast({
						title: '加载失败',
						mask: true,
					})
				})
			},
			//商圈类型
			getShoppingList() {
				// uni.showLoading({
				// 	title: '加载中',
				// 	mask: true,
				// })
				getShoppingListApi().then((res) => {
					if (res.code == 1) {
						this.businessArea = res.data;
						this.businessAreaActive = 0;
						this.findAllByList();

					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					uni.hideLoading();
					uni.showToast({
						title: '加载失败',
						mask: true,
					})
				})
			},

		},
		mounted(e) {
			/*自适应微信胶囊按钮*/
			this.custom = this.utils.getCustomNavData();
		},
		onLoad() {
			uni.$on('getSearchInput', (e) => {
				this.title = e;
				this.getSearchList()
			})
			this.getShoppingList()
			this.getViewList()
		}
	}
</script>

<style lang="scss">
	.content {
		.block.search-block {
			background: $color-primary;
			overflow: hidden;
		}

		.block.screen-block {
			display: flex;
			flex-direction: row;
			background: $color-primary;
			align-items: center;
			padding: 20rpx;

			.screen-item {
				display: flex;
				justify-content: center;
				color: $color-border-lighter;
				align-items: center;
				font-size: 30rpx;
				flex-grow: 1;

				.picker {
					display: flex;
					justify-content: center;
				}

				.picker.category {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}

				.picker.businessArea {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}

				.iconfont {
					margin-left: 16rpx;
					font-size: 28rpx;
					font-weight: normal;
				}

				.option.active {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}
			}
		}

		.block.label-block {
			display: flex;
			flex-direction: row;
			overflow-x: scroll;
			width: 100%;
			padding: 20rpx 0;

			.label-item {
				border-radius: 30rpx;
				color: $color-regular-text;
				font-size: 26rpx;
				padding: 10rpx 30rpx;
				background: $color-border-extralight;
				margin: 0 10rpx;
				flex: none;
			}
		}

		.block.list-block {
			padding: 0 30rpx;
			display: flex;
			flex-direction: column;

			.list-item {
				display: flex;
				flex-direction: row;
				padding: 30rpx 0;
				border-bottom: 1px solid #efefef;

				.photo {
					width: 230rpx;
					height: 280rpx;
					border-radius: 20rpx;
					margin-right: 20rpx;
				}

				.info-block {
					width: calc(100% - 250rpx);
					display: flex;
					flex-direction: column;
					position: relative;

					.name-block {
						display: flex;
						flex-direction: row;
						align-items: center;
						margin-bottom: 12rpx;

						.name {
							font-weight: bold;
							font-size: 34rpx;
							margin-right: 10rpx;
						}

						.grade {
							font-size: 24rpx;
							color: $color-secondary-text;
						}
					}

					.score-block {
						display: flex;
						align-items: center;
						margin-bottom: 12rpx;

						.score {
							flex-grow: 0;
							font-size: 34rpx;
							font-weight: bold;
							margin-right: 14rpx;
							background: url('@/static/bottom.png') no-repeat;
							background-position: center 85%;
							background-size: 80%;
						}

						.score-num {
							flex-grow: 0;
							font-size: 28rpx;
							color: $color-primary-text;
							margin-right: 10rpx;
						}

						.collect {
							font-size: 28rpx;
							color: $color-primary-text;
						}
					}

					.position-block {
						color: $color-secondary-text;
						font-size: 28rpx;
						margin-bottom: 12rpx;
					}

					.label-block {
						width: 100%;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;

						.label-item {
							font-size: 22rpx;
							padding: 0 10rpx;
							border: 1px solid #efefef;
							color: $color-secondary-text;
							border-radius: 8rpx;
							margin-right: 16rpx;
							margin-bottom: 10rpx;
						}
					}

					.price {
						font-size: 38rpx;
						display: flex;
						align-items: center;
						flex-direction: row;
						color: $color-danger;
						position: absolute;
						right: 0;
						bottom: 0;
						font-weight: bold;

						.money,
						.unit {
							font-size: 24rpx;
							font-weight: normal;
						}

						.money {
							margin-right: 4rpx;
						}

						.unit {
							color: $color-secondary-text;
							margin-left: 4rpx;
						}
					}
				}
			}

			.list-item.attractions:last-child {
				border: none;
			}
		}
	}
</style>
